﻿//----------------------------------------------------------------
// <copyright>
//    Top Do ---TOP API DEMO 示例系列
//    CLR Version: 2.0.50727.1434
//
//          回调地址页
//
//    By 淘宝旺旺ID: 幻影时空
//    Email:visionspace@st-soft.cn
//    Copyright (C) SpaceTime SoftWare , All rights reserved (www.st-soft.cn).
//
//    项目引用 需 TopSpace.Bll 类
// </copyright>
//----------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TopSpace.Bll;


public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["top_appkey"] != null)
        {
            //关于回调地址：http://open.taobao.com/dev/index.php/%E8%8E%B7%E5%8F%96SessionKey
            //关于用户验证：http://open.taobao.com/dev/index.php/%E7%94%A8%E6%88%B7%E9%AA%8C%E8%AF%81
            Response.Write(new Parser().GetParameters(Request.QueryString["top_parameters"].ToString(), "visitor_nick"));
            //验证回调地址参数是否合法，如果合法并保存用户数据至Cookie
            if (Sys.VerifyTopResponse(Request.QueryString["top_parameters"], Request.QueryString["top_session"], Request.QueryString["top_sign"],Config.Appkey,Config.Secret) == true)
            {
                //验证成功
                //从top_parameters为解析当前回调地址登录的nick
                string nick=new Parser().GetParameters(Request.QueryString["top_parameters"].ToString(),"visitor_nick");
                Client.SetCookies(nick, Request.QueryString["top_session"].ToString());
                //Response.Write("验证成功！");
                Response.Redirect("/admin/default.aspx");
            }
            else
            {
                //验证失败
                Response.Write("无效验证！");
            }
        }
        else
        {
            Response.Write("无效参数对象，登录验证失败");
        }
    }
}
